package day0224.exer;

import java.util.Objects;

public class Demo02 {

    public static void main(String[] args) {
        Phoenix[] phoenixs = new Phoenix[ 5 ];
        phoenixs[ 0 ] = new Phoenix( "凤凰卫士" , 150 , '男' );
        phoenixs[ 1 ] = new Phoenix( "凤凰女侠" , 220 , '女' );
        phoenixs[ 2 ] = new Phoenix( "凤凰大叔" , 220 , '男' );
        phoenixs[ 3 ] = new Phoenix( "凤凰骑士" , 180 , '男' );
        phoenixs[ 4 ] = new Phoenix( "凤凰天使" , 180 , '女' );

        sort(phoenixs);

        for (int i = 0; i < phoenixs.length; i++) {
            System.out.println(phoenixs[i]);
        }
    }


    public static void sort(Phoenix[] phoenixes) {
        for (int i = 0; i < phoenixes.length - 1; i++) {
            for (int j = 0; j < phoenixes.length - 1 - i; j++) {
                boolean b = (phoenixes[j].getAge() == phoenixes[j + 1].getAge()) && (phoenixes[j].getGender() > phoenixes[j + 1].getGender());
                if (phoenixes[j].getAge() > phoenixes[j + 1].getAge() || b){
                    Phoenix temp = phoenixes[j];
                    phoenixes[j] = phoenixes[j + 1];
                    phoenixes[j + 1] = temp;
                }

            }
        }
    }
}

class Phoenix {

    private String name ;
    private int age ;
    private char gender ;

    public Phoenix(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    // getter 和 setter

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "Phoenix{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || o instanceof Phoenix) {
            return false;
        }
        Phoenix phoenix = (Phoenix) o;
        return age == phoenix.age && gender == phoenix.gender && Objects.equals(name, phoenix.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, gender);
    }
}
